package com.example.emailWeb.Socket.SimpleDemo;

import com.example.emailWeb.Socket.CloseUtil;

import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class SenderDataBuffer {
    private Socket socket;
    private DataBuffer dataBuffer;

    public SenderDataBuffer(Socket socket, DataBuffer dataBuffer) {
        this.socket = socket;
        this.dataBuffer = dataBuffer;
        send();
    }

    public void send() {
        ObjectOutputStream os = null;
        try {
            os = new ObjectOutputStream(socket.getOutputStream());
            os.writeObject(dataBuffer);
            socket.getOutputStream().flush();
        } catch (
                IOException e) {
            e.printStackTrace();
        }finally {
            CloseUtil.closeAll(os,socket);
        }
    }
}
